Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
function returning [object Promise]

I'm trying to return the value of the first function, and use as variable on the second function, but it's showing this [object Promise].

addEventListener("fetch", event => {
  event.respondWith(fetchAndStream(event.request))
});

async function handleRequest(request) {
      var uri = request.url.replace(/^https:\/\/.*?\//gi, "/");
      return uri;
}

async function fetchAndStream() {

    uri = handleRequest();
    console.log(uri);
    // Fetch from origin server.
    let response = await fetch('http://blablabla.com/' + uri);

    const responseInit = {
        headers: {
            'Content-Type': 'application/octet-stream',
            'Content-Disposition': 'attachment; filename="file.m3u"',
        }
    };

    // ... and deliver our Response while that's running.
    return new Response(response.body, responseInit)
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are calling your functions incorrectly without arguments. Your handleRequest takes an argument request in your function declaration

async function handleRequest(request) 

In your event listener you are calling the callback with an argument

fetchAndStream(event.request)

But you don't take any arguments here.

async function fetchAndStream() {

    uri = handleRequest();
    console.log(uri);

Since you have used your function handleRequest with async. It returns a promise wrapper which will await the execution, which I have doubts it will complete from there. The wrapper is like a placeholder which will be filled once your promise completes but since you are not calling the functions properly. Hence you are getting the output.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda